import datetime
day_lst = {1:31,3:31,4:30,5:31,6:30,7:31,8:31,9:30\
          ,10:31,11:30,12:31}
year,month = input().split()
year = int(year)
month = int(month)
pre = datetime.date(year,month,1).isoweekday()
if month == 2:
    if (year % 4 == 0 and year % 100 != 0) \
        or  year % 400 == 0:
        day = 29
    else:
        day = 28
else:
    day = day_lst[month]
ret = ["Mon","Tue","Wed","Thu","Fir","Sat","Sun"]
for i in range(pre - 1):
    ret.append(' ')
for i in range(1,day+1):
    ret.append(i)
count = 0
for i in ret:
    print(f"{i:>5}",end = '')
    count += 1
    if count != 0 and count % 7 == 0:
        print()
